package cn.thoughtworks.school.entities.commands;

import cn.thoughtworks.school.entities.SurveyQuiz;
import cn.thoughtworks.school.entities.SurveyQuizChoices;
import cn.thoughtworks.school.entities.Tag;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Setter
@Getter
public class UpdateSurveyQuizCommand {

    private String description;

    private List<String> choices;

    private List<String> tags;

    public SurveyQuiz update(SurveyQuiz surveyQuiz,Set<Tag> tags) {
        surveyQuiz.setDescription(this.description);
        surveyQuiz.setUpdateTime(new Date());
        surveyQuiz.setChoices(updateChoices(surveyQuiz));
        surveyQuiz.setTags(tags);
        return surveyQuiz;
    }

    private List<SurveyQuizChoices> updateChoices(SurveyQuiz surveyQuiz) {
        List<SurveyQuizChoices> choices = surveyQuiz.getChoices();
        for (int i = 0; i < choices.size(); i++) {
            choices.get(i).setChoice(this.choices.get(i));
        }
        return choices;
    }
}
